package cn.school.hotel.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.school.hotel.dao.TripHotelOrderDao;
import cn.school.hotel.entity.TripHotelOrder;
import cn.school.hotel.service.TripHotelOrderService;
import cn.school.hotel.vo.ItripHotelOrderVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("tripHotelOrderService")
public class TripHotelOrderServiceImpl extends ServiceImpl<TripHotelOrderDao, TripHotelOrder> implements TripHotelOrderService {

    @Autowired
    private TripHotelOrderDao tripHotelOrderDao;

    @Override
    public IPage<TripHotelOrder> getHotelOrderPagelist(TripHotelOrder tripHotelOrder, Integer pageSize, Integer pageNum) {
        LambdaQueryWrapper<TripHotelOrder> wrapper = new LambdaQueryWrapper<>(tripHotelOrder);
        if (StrUtil.isNotEmpty(tripHotelOrder.getOrderNo())) {
            wrapper.eq(TripHotelOrder::getOrderNo, tripHotelOrder.getOrderNo());
        }
        wrapper.orderByDesc(TripHotelOrder::getCreationDate);

        return  page(new Page<>(pageNum, pageSize), wrapper);
    }

    @Override
    public ItripHotelOrderVO getHotelOrderDetail(String orderId) {
        return tripHotelOrderDao.getHotelOrderDetail(orderId);
    }
}
